﻿using System;
using System.Collections.Generic;
using System.Text;

/*
 * Author:Conis
 * Date:
 * Description:JSON的叶子节点
 */

namespace Coins.Squirrel.Nodous.JSON
{
    public class JSONNodousLeaf : JSONNodousComponent, INodousLeaf
    {
        /// <summary>
        /// 创建叶子节点
        /// </summary>
        /// <param name="name">节点名称</param>
        /// <param name="value">节点值</param>
        protected internal JSONNodousLeaf(string name, string value)
            : base(name, value) { }

        /// <summary>
        /// 创建前缀
        /// </summary>
        protected override void CreatePreifx()
        {
            this.container.Append(this.name).Append(":").Append(this.value);
        }

        /// <summary>
        /// 创建后缀
        /// </summary>
        protected override void CreateSuffix()
        {
            //如果当前节点不是最后一个节点，则加上逗号
            if (this.currentIndex != this.brotherCount)
            {
                this.container.Append(",");
            }
        }
    }
}
